// -----------------------------------------------------------
// Game Framework
// Copyright © 2024-2024 deadcycle. All rights reserved.
// Homepage: https://deadcycle.gitee.io
// Feedback: deadcycle@163.com
// -----------------------------------------------------------

#if ODIN_INSPECTOR

using System;
using System.Collections.Generic;
using System.Reflection;

using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;

using UnityEditor;

namespace ComponentAutoBind.Editor
{
    /// <summary>
    /// 使用Odin处理Inspector。
    /// </summary>
    [CustomEditor(typeof(Author))]
    public class AuthorInspector : OdinEditor { }

    public class AuthorAttrProcessor : OdinAttributeProcessor<Author>
    {
        private readonly Dictionary<string, Action<List<Attribute>>> m_FieldProcessorDict;

        public AuthorAttrProcessor()
        {
            m_FieldProcessorDict = new Dictionary<string, Action<List<Attribute>>>
            {
                { "m_Name", FieldName },
                { "m_NiceName", FieldNiceName },
                { "m_Homepage", FieldHomepage },
                { "m_Email", FieldEmail },
            };
        }

        public override void ProcessChildMemberAttributes(InspectorProperty parentProperty, MemberInfo member,
            List<Attribute> attributes)
        {
            if (member.MemberType == MemberTypes.Field &&
                m_FieldProcessorDict.TryGetValue(member.Name, out Action<List<Attribute>> fieldProcessor))
            {
                fieldProcessor.Invoke(attributes);
            }
        }

        private void FieldName(List<Attribute> attributes)
        {
            attributes.Add(new LabelTextAttribute("英文名"));
        }

        private void FieldNiceName(List<Attribute> attributes)
        {
            attributes.Add(new LabelTextAttribute("中文名"));
        }

        private void FieldHomepage(List<Attribute> attributes)
        {
            attributes.Add(new LabelTextAttribute("主页"));
        }

        private void FieldEmail(List<Attribute> attributes)
        {
            attributes.Add(new LabelTextAttribute("Email"));
        }
    }
}

#endif